//package proc2;

public class AreaAndLength {
    public static void main(String args[]) {
        double length, area;
        Circle circle = null;
        Triangle triangle;
        Ladder ladder;
        circle = new Circle(2);// 创建对象circle
        triangle = new Triangle(1, 2, 3);// 创建对象 triangle
        ladder = new Ladder(2, 4, 6);// 创建对象 ladder
        length = circle.getLength();// circle调用方法返回周长并赋值给length
        System.out.println("圆的周长:" + length);
        area = circle.getArea();// circle 调用方法返回面积并赋值给area
        System.out.println("圆的面积:" + area);
        length = triangle.getLength();// triangle调用方法返回周长并赋值给length
        System.out.println("三角形的周长:" + length);
        area = triangle.getArea();// triangle调用方法返回面积并赋值给area
        System.out.println("三角形的面积:" + area);
        area = ladder.getArea();// ladder 调用方法返回面积并赋值给area
        System.out.println("梯形的面积:" + area);
        triangle.setABC(12, 34, 1); // triangle调用方法设置3个边
        // 要求将3个边修改为12,34,1
        length = triangle.getArea();// triangle 调用方法返回面积并赋值给area
        System.out.println("三角形的面积:" + area);
        length = triangle.getLength();// triangle调用方法返回周长并赋值给length
        System.out.println("三角形的周长:" + length);
    }
}

class Triangle {
    double sideA, sideB, sideC, area, length;
    boolean boo;

    public Triangle(double a, double b, double c) {
        sideA = a;
        sideB = b;
        sideC = c;
        // 参数a.b.c分别赋值给sideA,sideB,sideC
        if ((a + b) > c && (a + c) > b && (b + c) > a) { // a.b.c构成三角形的条件表达式
            boo = true;// 给boo赋值
        } else {
            boo = false;// 给boo 赋值
        }
    }

    double getLength() {
        return length = sideA + sideB + sideC;// 方法体,要求计算出三角形周长 length的值并返回
    }

    public double getArea() {
        if (boo) {
            double p = (sideA + sideB + sideC) / 2.0;
            area = Math.sqrt(p * (p - sideA) * (p - sideB) * (p - sideC));
            return area;
        } else {
            System.out.println("不是一个三角形,不能计算面积");
            return 0;
        }
    }

    public void setABC(double a, double b, double c) {
        sideA = a;
        sideB = b;
        sideC = c; // 参数a赋值给 sideд//参数b赋值给 sideB//参数c赋值给 sidec
    }
}

class Ladder {
    double above, bottom, height, area;

    Ladder(double a, double b, double h) {
        above = a;
        bottom = b;
        height = h; // 构造方法体,将参数 a,b,c分别赋值给 above,bottom,height
    }

    double getArea() {
        return (above + bottom) * height / 2;// 方法体,要求计算出梯形面积 area 并返回
    }
}

class Circle {
    double radius, area;

    Circle(double r) {
        radius = r; // 构造方法体,参数r赋值给 radius 变量
    }

    double getArea() {
        return Math.PI * radius * radius; // 方法体,要求计算出圆形面积 area 并返回
    }

    double getLength() {
        return 2 * Math.PI * radius; // getarea方法体的代码,要求计算出圆形周长 1ength并返回
    }

    void setRadius(double newRadius) {
        radius = newRadius;
    }

    double getRadius() {
        return radius;
    }
}